<?php
/**
*@作者:MissZhang
*@邮箱:<787727147@qq.com>
*@创建时间:2021/7/6 下午12:09
*@说明:订单商品模型
*/
namespace app\common\model;
use think\facade\Db;
use think\Model;

class OrderGoods extends Model
{
    protected $pk = "rec_id";
    // 关闭时间戳自动写入
    protected $autoWriteTimestamp = false;
    public function getPkAttr() {
        return $this->pk;
    }
    public function goods(){
        return $this->hasOne(Goods::class, 'goods_id','goods_id');
    }
    public function store()
    {
        return $this->hasOne(Store::class, 'store_id', 'store_id');
    }
    //根据订单类型获取商品详情url
    public function getUrlAttr($value,$data) {
        $type=Db::name('order')->where('order_id',$data['order_id'])->value('type');
        if ($type==1){
            $url=url('Goods/goods_info',['id'=>$data['goods_id']])->build();
        }else{
            $url=url('Shop/jifen_goods_info',['goods_id'=>$data['goods_id']])->build();
        }
        return $url;
    }
}
